From c0bfe6dd482ef33ae4b1c51a840501581ed14707 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sun, 14 Aug 2005 20:10:47 +0000 Subject: [PATCH] adding tests --- ChangeLog | 7 +++ tests/Makefile.am | 31 ++++++++----- tests/float_to_u8.c | 96 ++++++++++++++++++++++++++++++++++++++++ tests/grayscale_to_rgb.c | 87 ++++++++++++++++++++++++++++++++++++ tests/u8_to_float.c | 87 ++++++++++++++++++++++++++++++++++++ 5 files changed, 296 insertions(+), 12 deletions(-) create mode 100644 tests/float_to_u8.c create mode 100644 tests/grayscale_to_rgb.c create mode 100644 tests/u8_to_float.c diff --git a/ChangeLog b/ChangeLog index e9ecb72..6eb4920 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-08-14 Øyvind Kolås + + * tests/float_to_u8.c + * tests/u8_to_float.c + * tests/grayscale_to_rgb.c: new files + * tests/Makefile.am: including preceding tests + 2005-08-14 Øyvind Kolås * babl/Makefile.am: added babl-instance.h, removed wilcard from diff --git a/tests/Makefile.am b/tests/Makefile.am index 1ad19d8..081b449 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,18 +1,25 @@ +TESTS = \ + float_to_u8 \ + grayscale_to_rgb \ + u8_to_float + +float_to_u8_SOURCES = float_to_u8.c +u8_to_float_SOURCES = u8_to_float.c +grayscale_to_rgb_SOURCES = grayscale_to_rgb.c + + +AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl +LDADD = $(top_builddir)/babl/libbabl.la -lm + + noinst_PROGRAMS = \ introspect \ - nop - -AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl + nop \ + $(TESTS) -introspect_SOURCES = \ - introspect.c -introspect_LDADD = $(top_builddir)/babl/libbabl.la +introspect_SOURCES = introspect.c +nop_SOURCES = nop.c -nop_SOURCES = \ - nop.c -nop_LDADD = $(top_builddir)/babl/libbabl.la -EXTRA_DIST= \ - .cvsignore +EXTRA_DIST = .cvsignore -TESTS=nop introspect diff --git a/tests/float_to_u8.c b/tests/float_to_u8.c new file mode 100644 index 0000000..5f392e2 --- /dev/null +++ b/tests/float_to_u8.c @@ -0,0 +1,96 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "babl.h" +#include "babl-internal.h" + +#define BUFFER_LENGTH 6 + +float float_buf[BUFFER_LENGTH]= +{ + 0.0, + 1.0, + -1.0, + 2.0, + 0.5, + 0.25, +}; + +unsigned char u8_buf [BUFFER_LENGTH]; +unsigned char u8_ref_buf [BUFFER_LENGTH]= +{ + 0, + 255, + 0, + 255, + 127, + 63, +}; + +int +test_float_to_rgb_u8 (void) +{ + BablFish *fish; + int i; + int OK=1; + + + fish = babl_fish ( + (Babl*) babl_pixel_format_new ( + "foo", + babl_model ("grayscale"), + babl_type ("float"), + babl_component ("luminance"), + NULL + ), + (Babl*) babl_pixel_format_new ( + "bar", + babl_model ("grayscale"), + babl_type ("u8"), + babl_component ("luminance"), + NULL + )); + + babl_fish_process (fish, + float_buf, u8_buf, + BUFFER_LENGTH); + + for (i=0; i +#include "babl-internal.h" + +#define BUFFER_LENGTH 4 +#define TOLERANCE 0.003 + +unsigned char u8_buf [BUFFER_LENGTH]= { 0, 255, 127, 63, }; +float float_ref_buf[BUFFER_LENGTH] = { 0.0, 1.0, 0.5, 0.25, }; +float float_buf [BUFFER_LENGTH]; + +int +test (void) +{ + BablFish *fish; + int i; + int OK=1; + + + fish = babl_fish ( + (Babl*) babl_pixel_format_new ( + "foo", + babl_model ("grayscale"), + babl_type ("u8"), + babl_component ("luminance"), + NULL + ), + (Babl*) babl_pixel_format_new ( + "bar", + babl_model ("grayscale"), + babl_type ("float"), + babl_component ("luminance"), + NULL + )); + + babl_fish_process (fish, + u8_buf, float_buf, + BUFFER_LENGTH); + + for (i=0; i TOLERANCE) + { + babl_log ("%i .. %f-%f=%f", + u8_buf[i], float_buf[i], float_ref_buf[i], + fabs (float_buf[i] - float_ref_buf[i]) + ); + OK=0; + } + } + if (!OK) + return -1; + return 0; +} + +int +main (int argc, + char **argv) +{ + babl_init (); + if (test()) + return -1; + babl_destroy (); + return 0; +} + + + -- 2.30.2